#@laybase() 
#define main()

<style>

.col-md-12 {
	position: relative;
	min-height: 100px;
}

.control {
	width: 80%;
    position: absolute;
    top: 30px;
    left: 15px;
}

.control select {
	display: inline-block;
    width: 16%;
}

.control input {
	display: inline-block;
    width: 12%;
}

.control button {
	margin-top: -3px;
}

</style>

<div class="col-md-12" id="app">
	<a href="/fuioudq/fuiouSign">签约</a>
	<div class="control">
		<select class="form-control" id="transst" style="display: inline-block;width: 20%;">
			<option value="">交易状态</option>
			<option value="0">交易未发送</option>
			<option value="1">交易已发送且成功</option>
			<option value="2">交易已发送且失败</option>
			<option value="3">交易发送中</option>
			<option value="7">交易已发送且超时</option>				
		</select>
		开始日期：<input class="date form-control" placeholder="开始日期" id="startDate" readonly="true" />
		结束日期：<input class="date form-control" placeholder="结束日期" id="endDate" readonly="true" />
		<button type="button" class="btn btn-default" id="searchbtn">搜索</button>
	</div>
	<table class="datatable" id="datatable" data-unique-id="id"></table>
</div>

<script src="/assets/js/bootstrap-table.min.js"></script>
<script src="/assets/js/bootstrap-table-zh-CN.js"></script>
<script>
	$(function(){
		var $table = $('#datatable'),
			searchDom = $("#searchbtn"),
			startDateDom = $("#startDate"),
			endDateDom = $("#endDate"),
			nowDate = new Date(),
			nextWeek = new Date(nowDate.getTime() - (86400000 * 6)),
			titles = [
			    {
					field: "merdt",
					title: "原请求日期"
				},
				{
					field: "orderno",
					title: "原请求流水"
				},
				{
					field: "accntno",
					title: "账号"
				},
				{
					field: "accntnm",
					title: "账户名称"
				},
				{
					field: "amt",
					title: "交易金额"
				},
				{
					field: "entseq",
					title: "企业流水号"
				},
				{
					field: "memo",
					title: "备注"
				},
				{
					field: "projectid",
					title: "项目 id"
				},
				{
					field: "state",
					title: "交易状态"
				},
				{
					field: "result",
					title: "交易结果"
				},
				{
					field: "reason",
					title: "结果原因"
				}
			]
	
		startDateDom.val($formatDate(nextWeek,"yyyy-MM-dd"))
		endDateDom.val($formatDate(nowDate,"yyyy-MM-dd"))
		
		$("#app").on("click",".date",laydate);
		
		$("#searchbtn").click(function(){
			//验证
			var startDate = startDateDom.val(),
				endDate = endDateDom.val()
				
			if(dateYz(startDate,endDate)){
				var params = {
					params: {
						"startdt": formatDate(new Date(startDate)),
						"enddt": formatDate(new Date(endDate))
					}
				}
				
				if(!_x.isEmpty($("#transst").val())){
					params.params.transst = $("#transst").val()
				}
				
				axios.get("/fuioudq/findRecord",params)
				.then(function(res){
					var data = res.data
					if(data.code == 0){
						_x.show_alert_sh(res.data.msg,false)
						return
					}
					console.log(data)
					var $data = data.data
					$table.bootstrapTable('load', $data)
				})
			}
			
		})
		
		axios.get("/fuioudq/findRecord",{
			params: {
				"startdt": formatDate(nextWeek),
				"enddt": formatDate(nowDate)
			}
		})
		.then(function(res){
			console.log(res.data)
			var data = [],
				$data = []
			if(res.data.code == 0){
				_x.show_alert_sh(res.data.msg,false)
			}else{
				data = res.data
				$data = data.data
			}
			
			createTable(titles,$data)
		})
		
		//创建表格
		function createTable(titles,data){
			$table.bootstrapTable({
				uniqueId: 'id',	
				search: true,
				pagination: true, 
	            pageSize: 20,
			    columns: titles,
			    data: data,
			    sortStable:true
			});		
		}
		
		//日期格式化
		function formatDate(date){
			var year = date.getFullYear(),
				month = date.getMonth() + 1,
				_date = date.getDate()
			if(month < 10)month = "0" + month
			if(_date < 10)_date = "0" + _date
			return year +""+ month +"" + _date
		}
		
		//日期验证
		function dateYz(start,end){
			var startTime = new Date(start).getTime(),
				endTime = new Date(end).getTime()
			if(endTime < startTime){
				_x.show_alert_sh("结束日期必须大于开始日期",false)
				return false
			}
			
			if(Math.floor((endTime - startTime)/(24*3600*1000)) > 15){
				_x.show_alert_sh("日期范围需要在15天以内",false)
				return false
			}
			
			if(endTime > (new Date().getTime() + 86400000)){
				_x.show_alert_sh("截止日期不能大于T+1日",false)
				return false
			}
			
			return true
		}
		
		function $formatDate(date,partten){
			if(/(y+)/.test(partten)){
				partten = partten.replace(RegExp.$1,date.getFullYear())
			}
			
			var o = {
				"M+": date.getMonth() + 1,
				"d+": date.getDate(),
				"h+": date.getHours(),
				"m+": date.getMinutes(),
				"s+": date.getSeconds()
			}
			
			for(var k in o){
				if(new RegExp("("+ k +")").test(partten)){
					partten = partten.replace(RegExp.$1,leftPadZero(o[k]))
				}
			}
			
			return partten
		}
		
		function leftPadZero(num){
			if(num < 10){
				return "0" + num
			}
			return num
		}
	})
</script>
#end